package com.falidos.visao.servlets;

import java.io.IOException;
import java.util.HashMap;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.falidos.controle.Controlador;

@WebServlet("/Cadastro")
public class Persistir extends SuperServlet {
	private static final long serialVersionUID = 1L;       
    
	@SuppressWarnings("unchecked")
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Controlador c = Controlador.obterInstancia();		
		HashMap<String, Object> dados = preparaDados(request);	
		String url = (request.getHeader("REFERER")).substring(34);
		if((Boolean) c.executarAcao(dados, null)){
			response.sendRedirect("/falidos.com/" + url + (url.lastIndexOf("?") < 0?"?":"&") + "sucesso=true");			
		}
		else{
			response.sendRedirect("/falidos.com/" + url + (url.lastIndexOf("?") < 0?"?":"&") + "?sucesso=false");	
		}
	}		
	
}
